package com.op.model.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.op.entity.Menu;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName： NavigationMenuTreeVo
 * Date： 2021/12/27 19:10
 *
 * @author 孤焰
 * @version 1.0
 **/

@ApiModel("导航栏菜单树")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class NavigationMenuTreeVo implements Serializable {
    private static final long serialVersionUID = 9095194112348605611L;

    @ApiModelProperty("主键id")
    private Long id;

    @ApiModelProperty("菜单名")
    private String name;

    @ApiModelProperty("菜单类型")
    private String type;

    @ApiModelProperty("路由路径")
    private String path;

    @ApiModelProperty("请求参数")
    private String query;

    @ApiModelProperty("组件路径")
    private String component;

    @ApiModelProperty("权限参数")
    private String permission;

    @ApiModelProperty("菜单图标")
    private String icon;

    @ApiModelProperty("子菜单")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<NavigationMenuTreeVo> children;

    public NavigationMenuTreeVo(Menu menu) {
        this.id = menu.getId();
        this.name = menu.getName();
        this.type = menu.getType();
        this.path = menu.getPath();
        this.query = menu.getQuery();
        this.component = menu.getComponent();
        this.permission = menu.getPermission();
        this.icon = menu.getIcon();
        this.children = menu.getChildren().stream()
                .map(NavigationMenuTreeVo::new)
                .collect(Collectors.toList());
    }
}
